package com.dog.basics.api.controller.mtkj;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.api.mtkj.ApiGoodsSkuAddDto;
import com.dog.basics.bean.dto.api.mtkj.ApiGoodsSkuEditDto;
import com.dog.basics.bean.vo.api.mtkj.ApiGoodsSkuFromVo;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.security.annotation.Inner;
import com.dog.basics.service.mtkj.IMtGoodsSkuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 商品sku表 前端控制器
 * </p>
 *
 * @author wph
 * @since 2020-11-09
 */
@RestController
@RequestMapping("/api/goodsSku")
@Api(value = "商品sku(商品规格)", tags = SwaggerConstants.API_ALL)
@AllArgsConstructor
public class MtGoodsSkuController {

    private final IMtGoodsSkuService goodsSkuService;

    /**
     * 根据商品id获取商品规格（sku）
     * @param goodId
     * @return
     */
    @ApiOperation(value = "获取商品规格", notes = "获取商品规格",tags = SwaggerConstants.API_GOODS)
    @ApiImplicitParam(value = "商品Id", name = "goodId", dataType = "Long", required = true)
    @PostMapping("/findGoodsSkuList")
    public R<IPage<ApiGoodsSkuFromVo>> findGoodsSkuList(PageParam page,@Valid Long goodId){
        return R.ok(goodsSkuService.findGoodsSku(page, goodId));
    }

    /**
     * 增加商品
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "增加商品sku", notes = "增加商品sku",tags = SwaggerConstants.API_GOODS)
    @PostMapping("/save")
    public R<Boolean> save(@Valid @RequestBody ApiGoodsSkuAddDto obj) {
        return R.ok(goodsSkuService.saveGoodsSku(obj));
    }

    /**
     * 修改商品
     * @param obj
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "修改商品sku", notes = "修改商品sku", tags = SwaggerConstants.API_GOODS)
    @PutMapping("/edit")
    public R<Boolean> edit(@Valid @RequestBody ApiGoodsSkuEditDto obj) {
        return R.ok(goodsSkuService.editGoodsSku(obj));
    }


    /**
     * 删除商品
     * @param goodSkuId
     * @return
     * @author hangdy
     */
    @ApiOperation(value = "删除商品sku", notes = "删除商品sku", tags = SwaggerConstants.API_GOODS)
    @ApiImplicitParam(value = "商品Id", name = "goodId", dataType = "Long", required = true)
    @DeleteMapping("/delete/{goodSkuId}")
    public R<Boolean> delete(@Valid @PathVariable("goodSkuId") Long goodSkuId) {
        return R.ok(goodsSkuService.deleteGoodsSku(goodSkuId));
    }
}
